package icu.makka.yygh.controller.api;

import icu.makka.yygh.model.hosp.Hospital;
import icu.makka.yygh.result.Result;
import icu.makka.yygh.service.DepartmentService;
import icu.makka.yygh.service.HospitalService;
import icu.makka.yygh.service.ScheduleService;
import icu.makka.yygh.service.impl.DepartmentServiceImpl;
import icu.makka.yygh.service.impl.HospitalServiceImpl;
import icu.makka.yygh.service.impl.ScheduleServiceImpl;
import icu.makka.yygh.vo.hosp.DepartmentVo;
import icu.makka.yygh.vo.hosp.HospitalQueryVo;
import icu.makka.yygh.vo.hosp.ScheduleOrderVo;
import icu.makka.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalServiceImpl hospitalService;

    @Autowired
    private DepartmentServiceImpl departmentService;

    @Autowired
    private ScheduleServiceImpl scheduleService;

    /**
     * 获取分页列表
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable("page") Integer page,
                               @PathVariable("limit") Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        log.info("查询医院列表，page={}，limit={}，hospitalQueryVo={}", page, limit, hospitalQueryVo);
        Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    /**
     * 根据医院名称查询
     * @param hosname
     * @return
     */
    @ApiOperation(value = "根据医院名称查询")
    @GetMapping("findByHosName/{hosname}")
    public Result findByHosname(@PathVariable("hosname") String hosname) {
        log.info("根据医院名称查询，hosname={}", hosname);
        List<Hospital> list = hospitalService.findByHosname(hosname);
        log.info("医院查询结果，{}", list);
        return Result.ok(list);
    }

    /**
     * 获取科室列表
     * @param hoscode
     * @return
     */
    @ApiOperation(value = "获取科室列表")
    @GetMapping("department/{hoscode}")
    public Result index(@PathVariable("hoscode") String hoscode) {
        log.info("获取科室列表，hoscode={}", hoscode);
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    /**
     * 医院预约挂号详情
     * @param hoscode
     * @return
     */
    @ApiOperation(value = "医院预约挂号详情")
    @GetMapping("/{hoscode}")
    public Result item(@PathVariable("hoscode") String hoscode) {
        log.info("医院预约挂号详情，hoscode={}", hoscode);
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }

    /**
     * 获取可预约排班数据
     * @param page
     * @param limit
     * @param hoscode
     * @param depcode
     * @return
     */
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page, @PathVariable Integer limit,
                                     @PathVariable String hoscode, @PathVariable String depcode) {
        log.info("获取可预约排班数据，page={}，limit={}，hoscode={}，depcode={}",page, limit, hoscode, depcode);
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    /**
     * 获取排班数据
     * @param hoscode
     * @param depcode
     * @param workDate
     * @return
     */
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode, @PathVariable String depcode, @PathVariable String workDate) {
        log.info("获取排班数据，hoscode={}，depcode={}，workDate={}", hoscode, depcode, workDate);
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    /**
     * 根据排班id获取排班数据
     * @param scheduleId
     * @return
     */
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getScheduleById(@PathVariable String scheduleId) {
        log.info("根据排班id获取排班数据，sheduleId={}", scheduleId);
        return Result.ok(scheduleService.getById(scheduleId));
    }

    /**
     * 根据排班id获取预约下单数据
     * @param scheduleId
     * @return
     */
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId")String scheduleId) {
        log.info("根据排班id获取预约下单数据");
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    /**
     * 获取医院签名信息
     * @param hoscode
     * @return
     */
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode) {
        log.info("获取医院签名信息，hoscode={}", hoscode);
        return hospitalService.getSignInfoVo(hoscode);
    }
}
